# -*- coding: utf-8 -*-
from Comps.WS import WS
from Comps.WSServer import WSServer

comps = {}

def Setup(key, ini, json, param):
    # 字典中存储的是函数引用，不是函数调用结果()
    setup_fns = {
        "ws": Setup_WS,
        "wss": Setup_WSServer,
    }
    # 使用 get 方法获取对应的函数，若没有则返回 default_action
    # 最后的 () 意味着调用获取到的函数
    func_to_call = setup_fns.get(key, Setup_Err)
    return func_to_call(ini, json, param)

def Setup_WS(ini, json, param):
    ws = WS()
    ws.setup(ini.get_section('ws'))
    ws.open()
    comps['ws'] = ws

def Setup_WSServer(ini, json, param):
    wss = WSServer()
    wss.setup(ini.get_section('wss'))
    wss.open()
    comps['wss'] = wss

def Setup_Err():
    print("key值错误")